﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace cpe.cpein.SERVER.Tools
{
    public static partial class ObjectConverter
    {
        /// <summary>
        /// Function used to convert a WS User to a Data User.
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public static DATA.User UserConverter(User user)
        {
            if (user == null)
                return null;

            return new DATA.User()
            {
                usr_id = user.Id,
                usr_name = user.Name,
                usr_lastname = user.Lastname,
                usr_email = user.Email,
                usr_isdeleted = user.IsDeleted,
                usr_login = user.Login,
                usr_password = user.Password
            };
        }

        /// <summary>
        /// Function used to convert a Data User to a WS User.
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public static User UserConverter(DATA.User user)
        {
            if (user == null)
                return null;

            return new User()
            {
                Id = user.usr_id,
                Name = user.usr_name,
                Lastname = user.usr_lastname,
                Email = user.usr_email,
                IsDeleted = user.usr_isdeleted,
                Login = user.usr_login,
                Password = user.usr_password
            };
        }

        /// <summary>
        /// Function used to convert a list of Data Users to a List of WS Users.
        /// </summary>
        /// <param name="users"></param>
        /// <returns></returns>
        public static List<User> UserConverter(List<DATA.User> users)
        {
            List<User> res = new List<User>();
            foreach (DATA.User us in users)
                res.Add(Tools.ObjectConverter.UserConverter(us));
            return res;
        }

        /// <summary>
        /// Function used to convert a list of WS Users to a List of Data Users.
        /// </summary>
        /// <param name="users"></param>
        /// <returns></returns>
        public static List<DATA.User> UserConverter(List<User> users)
        {
            List<DATA.User> res = new List<DATA.User>();
            foreach (User us in users)
                res.Add(Tools.ObjectConverter.UserConverter(us));
            return res;
        }
    }
}